
from data import dataProcess
import fileConfig as Conf
from classification import ModelManagement as Manger
from vector import Vectorization as Vector
import numpy as np
import gensim


"""
用于模型的调试 svm分类后的准确率在 95-98 之间 
"""

#数据处理分词
a = dataProcess.dataLoadToList(Conf.train_file_path)
train_list = a[0]
train_tag = a[1]
#print(train_tag)
cut_list = dataProcess.participle(train_list,Conf.stop_file_path)
#print(cut_list)




#训练向量化模型 使用这个把下面注释即可

"""
model = Vector.word2Vec_train(cut_list)
model.save("modelPlus3.model")
vector_list = [model.docvecs[i] for i in range(len(model.docvecs))]
print(np.array(vector_list))   # 向量化之后的文本
"""





#测试句子
model_path = "testModule.model"
sentence = "甜品的质量好象不如以前好，而且地方小服务态度差，比起南信的品质来说相差太远了。"

#sentence = "来了好几次广州都和南信擦肩而过，这次下定决心不管好远都要来尝。先去的是竹园竹升面，然后在上下九逛了一圈消食。8点多钟到店，人山人海，楼下只能现金，二楼可以微信支付。不用说，这种肯定是拼桌，要说一下，作为如此火爆的老字号，并没有因为生意好就傲慢，服务态度还是很好，会主动给你找位置。杨枝甘露，芒果用料很足，而且一点不酸，里面似乎还加了菠萝，做到了料足但又不至于十分粘稠。椰汁黑糯米，面上只看到一点黑糯米，但下面真的超多，椰汁甜度适中，没有添加剂的味道，糯米很香。一个人点了2份没有吃完，确实是吃不下了。价格很实惠"
#sentence = "位置在村里交通不方便，停车位好难找～鸡翅不好吃，是用店里的盐焗鸡翅炸的而已，这点不真诚，对不起炸鸡翅的身份！ 嗯 反而番薯饼不错，双皮奶不是很浓郁，姜撞奶也是一般，基本上大家推荐的我们都试了一下，没有想去第二次的冲动了。。"
cutSen = dataProcess.sentenceCut(sentence, Conf.stop_file_path)
sentenceVector = Vector.vectorizationWithModelOnSentence(cutSen, model_path)
print(sentenceVector)

#sentence2 = "这家的粽子真的很不错，是个值得打卡的地方 ！ 以后要常来鸭 } "
sentence2 = "本来说好的和朋友一起来打卡，可是天气突然下起了大雨，真服了， 结果到了这 点的茶花糕味道淡的不得了而且无比的硬，跟啃砖头一样！！ } "
cutSen2 = dataProcess.sentenceCut(sentence2, Conf.stop_file_path)
sentenceVector2 = Vector.vectorizationWithModelOnSentence(cutSen2, model_path)
print(sentenceVector2)


#模型预测
model = gensim.models.doc2vec.Doc2Vec.load(model_path)
train_vector_list = np.array([model.docvecs[i] for i in range(len(model.docvecs))])
print(train_vector_list)
model_config = {"model_name":"SVM","proportion":0.3}
manger = Manger()
result = manger.modelPredict([sentenceVector], train_vector_list,train_tag,model_config,False)


test_data_frame = dataProcess.dataLoadToList("D:\\java\\NLP\\CommentStatistics-Publisher\\src\\main\\resources\\tdata\\TestData.xlsx")[0]
cut_test_list = dataProcess.participle(test_data_frame,Conf.stop_file_path)

#测试数据向量化
vector = Vector.vectorizationWithModel("testModule.model",cut_test_list)
test_result = manger.modelPredict(np.array(vector),train_vector_list,train_tag,model_config,True)
print(test_result)
#模型评价

print(result)




